package com.lcu.bos.web.action;

import com.lcu.bos.modle.Noticebill;
import com.lcu.bos.service.INoticebillService;
import com.lcu.bos.web.action.base.BaseAction;
import com.lcu.crm.domain.Customer;
import com.lcu.crm.service.CustomerService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * 业务通知单
 */
public class NoticebillAction extends BaseAction<Noticebill>{
    @Autowired
    private CustomerService customerService;
    @Autowired
    private INoticebillService noticebillService;
    private String tel;  //电话
    public void setTel(String tel) {
        this.tel = tel;
    }
    public void findCustomerByTel() throws IOException {
        //远程调用
        Customer customer = customerService.findCustomerByTel(tel);
        //3.返回json格式数据
        JsonConfig config=new JsonConfig();
        //sf-json框架可以把不需要转成json的数据排除掉
        //config.setExcludes(new String[]{"decidedzone","region"});
        JSONObject jb=JSONObject.fromObject(customer,config);
        //创建一个json对象
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setHeader("Content-Type","text/json;charset=utf-8");
        response.getWriter().write(jb.toString());
    }

    private String decidedzoneId;

    public void setDecidedzoneId(String decidedzoneId) {
        this.decidedzoneId = decidedzoneId;
    }

    public String save() {
        //获取表单数据
        System.out.println(getModel());
        //2.设置客服的id(使用工具栏  在service中设置更加便捷)
        //保存
        noticebillService.save(getModel(),decidedzoneId);
        return SUCCESS;
    }

    @Override
    public String delete() throws IOException {
        return null;
    }

    @Override
    public String update() throws UnsupportedEncodingException {
        return null;
    }

    @Override
    public String get() {
        return null;
    }

    @Override
    public String findAll() {
        return null;
    }
}
